<extend name="./public/frame.html"/>
<block name="content">
<form class="layui-form layui-form-pane1" action="" method="post">
	<div class="layui-form-item">
		<label class="layui-form-label">活动名称</label>
		<div class="layui-input-block">
			<input type="text" name="title" lay-verify="required|title" required placeholder="请输入活动名称" autocomplete="off" class="layui-input">
		</div>
	</div>
	<div class="layui-form-item" style="display: none;">
		<label class="layui-form-label" style="width: 80px;">模式</label>
		<div class="layui-inline">
			<input type="radio" name="model" lay-filter="model" value="1" title="小马出行">
			<input type="radio" name="model" lay-filter="model" value="2" title="蜜马出行" checked>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label" style="width: 90px;padding-right:5px;">领取途径</label>
		<div class="layui-inline">
			<select id="is_recommed" name="is_recommed" lay-filter="is_recommed">
				<?php foreach($isRecommedName as $key=>$value):?>
				<option value="<?php echo $key;?>"><?php echo $value;?></option>
				<?php endforeach;?>
			</select>
		</div>
	</div>

	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">优惠类型</label>
			<div class="layui-input-inline" style="width: 200px;">
				<select name="money_type" lay-filter="money_type" id="money_type">
					<?php foreach($moneyTypeName as $key=>$value):?>
					<option value="<?php echo $key;?>" id="money_type<?php echo $key;?>"><?php echo $value;?></option>
					<?php endforeach;?>
				</select>
			</div>
		</div>
	</div>
	<div class="layui-form-item" id="money_content">
		<div class="layui-inline">
			<label class="layui-form-label">满</label>
			<div class="layui-input-inline" style="width: 200px;">
				<input type="text" name="over_money" id="over_money" autocomplete="off" class="layui-input" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">
			</div>
			<div class="layui-form-mid">减</div>
			<div class="layui-input-inline" style="width: 200px;">
				<input type="text" name="money" id="money" value="" class="layui-input" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">
			</div>
			<div class="layui-form-mid">元</div>
		</div>
	</div>

	<div class="layui-form-item" id="money_content_zhekou" style="display: none;">
		<div class="layui-inline">
			<label class="layui-form-label">满</label>
			<div class="layui-input-inline" style="width: 200px;">
				<input type="text" name="over_money_zhekou" id="over_money_zhekou" autocomplete="off" class="layui-input">
			</div>
			<div class="layui-form-mid">打</div>
			<div class="layui-input-inline" style="width: 200px;">
				<input type="text" name="money_zhekou" id="money_zhekou" value="" class="layui-input">
			</div>
			<div class="layui-form-mid">折</div>
		</div>
	</div>
	<div class="layui-form-item" id="price_money" style="display: none;">
		<div class="layui-inline">
			<label class="layui-form-label">奖励金额</label>
			<div class="layui-input-inline" style="width: 200px;">
				<input type="text" name="cash_money" id="cash_money" autocomplete="off" class="layui-input">
			</div>
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">活动日期</label>
			<div class="layui-input-inline" style="width: 200px;">
				<input type="text" name="start_time" lay-verify="required|start_time"  class="layui-input" id="test6-1">
			</div>
			<div class="layui-form-mid">-</div>
			<div class="layui-input-inline" style="width: 200px;">
				<input type="text" name="end_time" lay-verify="required|end_time" class="layui-input" id="test6-2">
			</div>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">有效日期</label>
		<div class="layui-inline">
		    <input type="radio" name="type_day" lay-filter="type_day" value="1" title="固定日期模式" checked>
		    <input type="radio" name="type_day" lay-filter="type_day" value="2" title="非固定模式" >
		</div>
	</div>
	<div class="layui-form-item" id="old">
		<label class="layui-form-label"></label>
		<div class="layui-inline">
			<div class="layui-input-inline" style="width: 200px;">
				<input type="text" name="valid_start_time"   class="layui-input" id="test6-3">
			</div>
			<div class="layui-form-mid">-</div>
			<div class="layui-input-inline" style="width: 200px;">
				<input type="text" name="valid_end_time" class="layui-input" id="test6-4">
			</div>
		</div>
	</div>
	<div class="layui-form-item" id="new" style="display: none">
		<label class="layui-form-label"></label>
		<div class="layui-inline">
			<label class="layui-form-label" style="width:auto">自用户领取之日起</label>
			<div class="layui-input-inline" style="width: 50px;">
				<input type="text" name="start_day"   class="layui-input">
			</div>
			<label class="layui-form-label" style="width:auto">天后生效,有效期</label>
			<div class="layui-input-inline" style="width: 50px;">
				<input type="text" name="duration_day" class="layui-input">
			</div>
			<label class="layui-form-label" style="width:auto">天.</label>
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">活动类型</label>
			<div class="layui-input-inline" style="width: 200px;">
				<select name="order_type" lay-filter="order_type">
					<?php foreach($orderTypeName as $key=>$value):?>
					<option value="<?php echo $key;?>"><?php echo $value;?></option>
					<?php endforeach;?>
				</select>
			</div>
		</div>
	</div>
	<div class="layui-form-item" id="newUser" style="display: none;">
		<label class="layui-form-label">只为新用户</label>
		<div class="layui-input-block">
			<input type="checkbox" name="is_newuser" id="is_newuser" value="0" lay-skin="switch" lay-filter="switchCheck" lay-text="ON|OFF" >
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">推送城市</label>
		<div class="layui-input-block fa">
			<input type="checkbox" data-type="all" title="全部" lay-verify="required|region">
			<div id="region">
				<volist name="list" id="v">
				<input type="checkbox" name="region[]" title="{$v.zone_name}" value="{$v.city_id}" class="item_child" >
				</volist>
			</div>
		</div>
	</div>
	<div class="layui-form-item dianziweilan" style="display: none;">
		<label class="layui-form-label">电子围栏</label>
		<div class="layui-input-block dianzi">
			<input type="checkbox" data-type="allDianzi" title="全部" lay-verify="required|region">
			<div id="regionaa">
				<?php foreach($interRailList as $key=>$value):?>
				<input type="checkbox" name="inter_rail[]" title="{$value.rail_name}" value="{$value.id}" class="inter_rail">
				<?php endforeach;?>
			</div>
		</div>
	</div>
	<div class="layui-form-item layui-form-text">
		<label class="layui-form-label">请填写活动描述</label>
		<div class="layui-input-block">
			<textarea placeholder="请输入内容" class="layui-textarea" name="comment"></textarea>
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-input-block">
			<button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
			<button type="reset" class="layui-btn layui-btn-primary">重置</button>
		</div>
	</div>
</form>

<script>
layui.use('laydate', function(){
	var laydate = layui.laydate;
	//墨绿主题
	laydate.render({
	elem: '#test6-1' //指定元素
	,type: 'date'
	,theme: 'molv'
	//,range: true
	,trigger: 'click'
	});

	laydate.render({
		elem: '#test6-2' //指定元素
		,type: 'date'
		,theme: 'molv'
		//,range: true
		,trigger: 'click'
	});
	laydate.render({
		elem: '#test6-3' //指定元素
		,type: 'date'
		,theme: 'molv'
		//,range: true
		,trigger: 'click'
	});
	laydate.render({
		elem: '#test6-4' //指定元素
		,type: 'date'
		,theme: 'molv'
		//,range: true
		,trigger: 'click'
	});

});
layui.use('form', function(){
	var form = layui.form;
	//事件监听
	form.on('select(order_type)', function(data){
		var type = data.value;
		$.post('/admin/coupon/get_open_region',{'type':type},function(res){
			$("#region").html(res)
			form.render();
		})
		if(type == 3){
			$(".dianziweilan").css('display','');
		}else{
			$(".dianziweilan").css('display','none');
		}
	})
	form.on('checkbox', function(data){
		var type = $(this).data('type');
		if(type == 'all'){
			var child = $('.fa').find('.item_child');
			child.each(function(index, item){
				item.checked = data.elem.checked;
			});
			form.render('checkbox');
		}else if(type == 'allDianzi'){
			var child = $('.dianzi').find('.inter_rail');
			child.each(function(index, item){
				item.checked = data.elem.checked;
			});
			form.render('checkbox');
		}
	});
	form.on('switch(switchCheck)', function(data){
		if(!this.checked){
			var value = 0;
		}else{
			var value = 1;
		}
		$("#is_newuser").val(value);
	});
	form.on('select(money_type)',function(data){
		if(data.value == 1){
			$("#money_content").css('display','');
			$("#money_content_zhekou").css('display','none');
			$("#money_zhekou").val('');
			$("#over_money_zhekou").val('');
		}else if(data.value == 2){
			$("#money_content").css('display','none');
			$("#money_content_zhekou").css('display','');
			$("#money").val('');
			$("#over_money").val('');
		}
	})
	//是否只针对新用户操作
	form.on('select(is_recommed)', function(data){
		if(data.value == 1){
			$("#newUser").css('display','none');
		}else{
			$("#newUser").css('display','');
		}
		if(data.value == 6){
			$('#money_type2').attr("disabled",'disabled');
			$('#money_type1').attr("disabled",'disabled');
			$("#money_type").val("3");
			$('#price_money').css('display','');
			$('#money_content').css('display','none');
			$('#money_content_zhekou').css('display','none');
		}else{
			$("#money_type").val("1");
			$('#money_type2 ').removeAttr("disabled");
			$('#money_type1 ').removeAttr("disabled");
			$('#price_money').css('display','none');
			$('#money_content').css('display','');
			$('#money_content_zhekou').css('display','none');
			$('#money_type3').attr("disabled",'disabled');
		}
		form.render('select');
	});
	form.on('radio(type_day)', function(data){
		if(data.value == 1){
			$("#old").show();
			$("#new").hide();
		}else if(data.value == 2){
			$("#old").hide();
			$("#new").show();
		}
	});
	form.on('radio(model)', function(data){
		if(data.value == 1){
			$('#money_type2').attr("disabled",'disabled');
		}else if(data.value == 2){
			$('#money_type2').removeAttr("disabled");
		}
		form.render('select');
	});

	//监听提交
	form.verify({
		title: function(value){
			if(value.length < 1){
				return '标题不能为空';
			}
		}
		,end_time: function(value){
			if(value < $("input[name='start_time']").val()){
				return '时间不一致';
			}
		}
		,region:function(value){
			var child = $('.fa').find('.item_child');
			var i=0;
			child.each(function(index, item){
				if($(this).attr('checked')){
					i = i + parseInt($(this).val());
				}
			});
			if(i == 0){
				return '未选择推送城市';
			}
		}
	});
	form.on('submit(*)', function(data){
		var money_type = $("#money_type").val();
		if(money_type == 1){
			var money = $("#money").val();
			var over_money = $("#over_money").val();
			if(money == '' || over_money == ''){
				layer.msg('现金券满减金额填写不能为空',{icon: 5});return false
			}
			if(money < 0 || over_money < 0){
				layer.msg('现金券满减金额填写不能小于0',{icon: 5});return false
			}
			if(over_money*1 > money*1){
				//layer.msg('现金券优惠金额不能大于满减金额',{icon: 5});return false
			}
		}else if(money_type == 2){
			var money_zhekou = $("#money_zhekou").val();
			var over_money_zhekou = $("#over_money_zhekou").val();
			if(money_zhekou == '' || over_money_zhekou == ''){
				layer.msg('折扣券信息填写不能为空',{icon: 5});return false
			}
			if(money_zhekou <= 0 || over_money_zhekou <= 0){
				layer.msg('折扣券信息填写不能为0或者小于0',{icon: 5});return false
			}
			if(money_zhekou*1 > 10){
				layer.msg('折扣券优惠不能大于10',{icon: 5});return false
			}
		}
	});
});

</script>
</block>
